#include <QApplication>
#include <iostream>
#include <QString>

#include "SQLHelper.h"
#include "LogginDialog.h"
#include "User.h"

User user;  // 登陆用户
LogginDialog *loggin_dialog;
MainWindow *main_window;

void init_database()
{
    SQLHelper sql_helper;
    sql_helper.connect();
    sql_helper.creat_table();
    QString sql = "INSERT INTO `library_ms`.`user` (`id`, `name`, `passwd`, `create_time`, `authority`) VALUES ('0', 'admin', 'admin', '0', '0');";
    sql_helper.exec_sql(sql);
}

void loggin_callback()
{
    delete loggin_dialog;
    main_window->init_view_main();
    main_window->show();
}

int main(int argc, char *argv[])
{

    QApplication a(argc, argv);

    init_database();   //初始化数据库

    loggin_dialog = new LogginDialog(&user, loggin_callback);
    main_window = new MainWindow(&user);

    loggin_dialog->init_view_main();
    loggin_dialog->show();

    return a.exec();
}

